// Sky.h: interface for the Sky class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(SKY_H)
#define SKY_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <stdlib.h>

/* OpenGL Includes */
#ifdef FREEGLUT_IS_PRESENT
#  include <GL/freeglut.h>
#else
#  ifdef __APPLE__
#    include <GLUT/glut.h>
#  else
#    include <GL/glut.h>
#  endif
#endif

#include <plib/ssg.h>

#ifndef PLIB_STUFF
#define PLIB_STUFF
#include <plib/ssgAux.h>
#include <plib/ssgaSky.h>
#endif

#include "Defines.h"

/* ------------- SKY ---------------- */

//comment this if you don't want clouds!!!
#define CLOUDY_DAY
//#define SUN_MOVING

/* SKYDOME DIMENSIONS */
#define HOR_RADIUS 80000
#define VER_RADIUS 80000 

/* SUN SIZE & POSITION (in degrees)*/
#define SUN_DECLINATION		60
#define SUN_SIZE			500
#define SUN_DISTANCE		80000		
#define SUN_RIGHT_ASCENSION 180     // N:90 E:360 S:270 W:180

/* MOON POSITION & SIZE (declination in degrees) */
#define MOON_DECLINATION		10
#define MOON_SIZE				500
#define MOON_DISTANCE			80000
#define MOON_RIGHT_ASCENSION	170

/* MAX NUMBER OF CLOUD LAYERS (never modify!) */
#define MAX_CLOUDS 3

/* CLOUDS DATA */
#define CLOUDS_SPAN			160000
#define CLOUDS_ELEVATION_1	4500
#define CLOUDS_ELEVATION_2	4500 
#define CLOUDS_ELEVATION_3	4500
#define CLOUDS_THICKNESS    50
#define CLOUDS_TRANSITION   50

/* STARS */
#define NUMBER_OF_STARS 5000

/* CELESTIAL BODIES */
#define MAX_BODIES 2


/* COLOURS */
/*
static sgVec4 black             = { 0.0f, 0.0f, 0.0f, 1.0f } ;
static sgVec4 red				= { 1.0f, 0.0f, 0.0f, 1.0f } ;
static sgVec4 green				= { 0.0f, 1.0f, 0.0f, 1.0f } ;
static sgVec4 blue				= { 0.0f, 0.0f, 1.0f, 1.0f } ;
static sgVec4 white             = { 1.0f, 1.0f, 1.0f, 1.0f } ;
static sgVec4 translucent_white = { 1.0f, 1.0f, 1.0f, 0.8f } ;

static sgVec4 base_sky_color    = { 0.39f, 0.50f, 0.74f, 1.0f } ;
static sgVec4 base_fog_color    = { 0.84f, 0.87f, 1.00f, 1.0f } ;

static sgVec4 base_ambient      = { 0.2f, 0.2f, 0.2f, 1.0f } ;
static sgVec4 base_diffuse      = { 1.0f, 1.0f, 1.0f, 1.0f } ;
static sgVec4 base_specular     = { 1.0f, 1.0f, 1.0f, 1.0f } ;
 */

class Sky  
{
public:
	Sky();
	virtual ~Sky();

	void				updateSky(float dt);

	//getters
	ssgaSky*			getSky();
	ssgaCelestialBody*	getBody(int i);
	int					getNstars();
	int					getNplanets();
	GLfloat				getFogDensity();
	double				getSkyBrightness();
	double				getSceneBrightness();
	GLfloat*			getFogColor();

	void				preDraw();
	void				postDraw();

	void				setCameraPosition(sgCoord campos);
	void				enableFog();
	void				disableFog();
	void				getSunPosition(sgCoord *sunpos);
	ssgTransform*		getTransform(void);

private:
	ssgaSky				*sky;
	ssgaCelestialBody	*bodies[MAX_BODIES];
    ssgaCloudLayer      *clouds[MAX_CLOUDS];

	int					nstars ;
	sgdVec3				*star_data;

    int					nplanets;
	sgdVec3				*planet_data;
	const char				*bodyNameList[3];
	const char				*cloudNameList[4];
	int					curr_body;
	int					curr_cloud;

	sgVec4				sky_color ;
	GLfloat				fog_color[4] ;
	sgVec4				cloud_color ;

	double				m_log01;
	double				sqrt_m_log01;
	double				sol_angle;
	double				sky_brightness;
	double				scene_brightness;

	sgVec4				scene_ambient;
	sgVec4				scene_specular;
	sgVec4				scene_diffuse;

	sgCoord				campos;

	sgCoord				solpos;
	ssgTransform		*sunTransform;

	int					fogEnabled;
};

#endif // !defined(SKY_H)
